package com.ruoyi.ptsp.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.ptsp.domain.Pttj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.ptsp.domain.Ptsp;
import com.ruoyi.ptsp.service.IPtspService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 拼团商品Controller
 * 
 * @author ruoyi
 * @date 2024-08-06
 */
@RestController
@RequestMapping("/ptsp")
public class PtspController extends BaseController
{
    @Autowired
    private IPtspService ptspService;

    /**
     * 查询拼团商品列表
     */
    @RequiresPermissions("ptsp:ptsp:list")
    @GetMapping("/list")
    public TableDataInfo list(Ptsp ptsp)
    {
        startPage();
        List<Ptsp> list = ptspService.selectPtspList(ptsp);
        return getDataTable(list);
    }

    /**
     * 导出拼团商品列表
     */
    @RequiresPermissions("ptsp:ptsp:export")
    @Log(title = "拼团商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Ptsp ptsp)
    {
        List<Ptsp> list = ptspService.selectPtspList(ptsp);
        ExcelUtil<Ptsp> util = new ExcelUtil<Ptsp>(Ptsp.class);
        util.exportExcel(response, list, "拼团商品数据");
    }

    /**
     * 获取拼团商品详细信息
     */
    @RequiresPermissions("ptsp:ptsp:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ptspService.selectPtspById(id));
    }

    /**
     * 新增拼团商品
     */
    @RequiresPermissions("ptsp:ptsp:add")
    @Log(title = "拼团商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Ptsp ptsp)
    {
        return toAjax(ptspService.insertPtsp(ptsp));
    }

    /**
     * 修改拼团商品
     */
    @RequiresPermissions("ptsp:ptsp:edit")
    @Log(title = "拼团商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Ptsp ptsp)
    {
        return toAjax(ptspService.updatePtsp(ptsp));
    }

    /**
     * 删除拼团商品
     */
    @RequiresPermissions("ptsp:ptsp:remove")
    @Log(title = "拼团商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ptspService.deletePtspByIds(ids));
    }

    @GetMapping("/count")
    public List<Pttj> getTj(Pttj pttj){
    	return ptspService.getTj(pttj);
    }
}
